<template>
    <div>
        <div id="slider" class="mui-slider">
				<div id="sliderSegmentedControl" class="mui-scroll-wrapper mui-slider-indicator mui-segmented-control mui-segmented-control-inverted">
					<div class="mui-scroll">
						<a @click="loadPhotos(item.id)" v-for="item in titles" :key="item.id" :class="['mui-control-item',item.id == 1?'mui-active':'']" href="#item1mobile" data-wid="tab-top-subpage-1.html">
							{{item.title}}
						</a>
					</div>
				</div>
			</div>
        <ul class="photo_list">
            <router-link tag="li" :to="'/home/photoSharing/imgAndTxt/'+item.com" v-for="item in url" :key="item.id">
                <div class="black_opacity">
                <h1>{{item.title}}</h1>
                <p>{{item.content}}</p>
                </div>
                <img v-lazy="item.url">
            </router-link>
        </ul>
    </div>
</template>
<script>
import mui from '../../lib/mui/js/mui.js'
export default {
    data:function () {
        return {
            titles:'',
            url:[],
        }
    },
    methods:{
        loadTitle:function () {
            this.$http.get('lib/interface4_phototitle.json').then(function(res){
                if(res.body.status == "ok"){
                    this.titles = res.body.titles;
                }
            });
        },
        loadPhotos:function (id) {
            this.$http.get('lib/interface5_photourl.json').then(function (res) {
               if (res.body.status == "ok"){
                   if(id != 1){
                       this.url = res.body.photos[id-2].urls;
                   }else{
                       res.body.photos.forEach((item)=>{
                            this.url = this.url.concat(item.urls);
                       });
                   }
               }
            });
        }
    },
    mounted:function () {
        mui('.mui-scroll-wrapper').scroll({
            deceleration: 0.0005 //flick 减速系数，系数越大，滚动速度越慢，滚动距离越小，默认值0.0006
        });  
    },
    created:function () {
        this.loadTitle();
        this.loadPhotos(1);
    }
}
</script>
<style lang="scss" scoped>
// chrome为提高滑动流畅度得加此样式
*{
   touch-action: pan-y; 
}
.photo_list{
    margin: 0;
    padding: 6px 32px 6px 32px;
    li{
        margin-bottom: 16px;
        background: #ccc;
        text-align: center;
        list-style: none;
        height: 420px;
        box-shadow: 0 0 6px #999;
        position: relative;
        .black_opacity{
            position: absolute;
            bottom: 0;
            width: 100%;
            padding: 5px;
            background-color:rgba(0,0,0,0.4);
            max-height: 84px;
            h1,p{
                color: #eee;
                font-size: 12px;
                text-overflow: ellipsis;
                white-space: nowrap; 
                overflow: hidden;
            }
        }
        img{
            width: 100%;
            height: 100%;
            vertical-align: middle;
        }
        img[lazy=loading] {
        width: 40px;
        height: 300px;
        margin: auto;
        }
    }
}
</style>